package com.wakala.employment.adapter.poi;

import com.wakala.employment.R;
import com.wakala.employment.adapter.base.broccoli.BroccoliRecyclerAdapter;
import com.wakala.employment.adapter.bean.PoiEntity;
import com.wakala.employment.utils.PlaceholderHelper;
import com.xuexiang.xaop.annotation.MemoryCache;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;

import java.util.ArrayList;
import java.util.List;

import me.samlss.broccoli.Broccoli;

/**
 * @author xuexiang
 * @since 2019/4/7 下午12:06
 */
public class PoiListAdapter extends BroccoliRecyclerAdapter<PoiEntity> {
    /**
     * 是否是加载占位
     */
    private boolean mIsAnim;

    public PoiListAdapter(boolean isAnim) {
        super(getEmptyPoiItem());
        mIsAnim = isAnim;
    }

    @MemoryCache
    public static List<PoiEntity> getEmptyPoiItem() {
        List<PoiEntity> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            list.add(new PoiEntity());
        }
        return list;
    }


    @Override
    protected int getItemLayoutId(int viewType) {
        return R.layout.layout_poi_item;
    }


    @Override
    protected void onBindData(RecyclerViewHolder holder, PoiEntity model, int position) {
        holder.text(R.id.tv_title, model.getTitle());
        holder.text(R.id.tv_summary, model.getAddress());
    }

    /**
     * 绑定占位控件
     *
     * @param holder
     * @param broccoli
     */
    @Override
    protected void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli) {
        if (mIsAnim) {
            broccoli
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_title)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_summary)));
        } else {
            broccoli.addPlaceholders(
                    holder.findView(R.id.tv_title),
                    holder.findView(R.id.tv_summary)
            );
        }
    }

}
